package pers.patterns.yang;

import pers.atomic.yang.operation.Number;
import pers.patterns.yang.adapter.MusicPlayer;
import pers.patterns.yang.adapter.PlayerAdapter;
import pers.patterns.yang.decorate.Person;
import pers.patterns.yang.decorate.Shirt;
import pers.patterns.yang.decorate.Student;
import pers.patterns.yang.decorate.Trousers;
import pers.patterns.yang.factory.Computer;
import pers.patterns.yang.factory.ComputerFactory;
import pers.patterns.yang.observer.Customer;
import pers.patterns.yang.observer.CustomerA;
import pers.patterns.yang.observer.CustomerB;
import pers.patterns.yang.observer.NewspaperOffice;
import pers.patterns.yang.proxy.Houser;
import pers.patterns.yang.proxy.HouserProxy;
import pers.patterns.yang.proxy.Tenant;
import pers.patterns.yang.responsibility.AHandler;
import pers.patterns.yang.responsibility.BHandler;
import pers.patterns.yang.responsibility.Post;
import pers.patterns.yang.responsibility.PostHandler;
import pers.patterns.yang.singleton.Single;
import pers.patterns.yang.strategy.Calculator;
import pers.patterns.yang.strategy.OperationAdd;
import pers.patterns.yang.strategy.OperationSub;
import pers.patterns.yang.template.Cook;
import pers.patterns.yang.template.CookPotato;
import pers.patterns.yang.template.CookTomato;

public class Main {
    public static void main(String[] args) throws InterruptedException {
        Calculator add = new Calculator(new OperationAdd());
        System.out.println(add.doOperation(5,2));

        Calculator sub = new Calculator(new OperationSub());
        System.out.println(sub.doOperation(5,2));

        Person s = new Student();
        s = new Shirt(s);
        s = new Trousers(s);
        s.show();
        System.out.println("累计消费" + s.cost());

        NewspaperOffice newspaperOffice = new NewspaperOffice();
        Customer customerA = new CustomerA();
        Customer customerB = new CustomerB();

        newspaperOffice.addCustomer(customerA);
        newspaperOffice.addCustomer(customerB);

        newspaperOffice.newspaper();

        for (int i = 0; i < 10; i++) {
            new Thread(()-> {
                Single.getInstance();
            }).start();
        }

        ComputerFactory computerFactory = new ComputerFactory();
        Computer a = computerFactory.createdComputer("a");
        Computer b = computerFactory.createdComputer("b");

        MusicPlayer player = new PlayerAdapter();
        player.play("mp3", "xxx.mp3");
        player.play("wma", "xxx.wma");

        HouserProxy houserProxy = new HouserProxy(new Tenant());
        houserProxy.findHouse();

        Cook ct = new CookTomato();
        ct.cook();
        Cook cp = new CookPotato();
        cp.cook();

        PostHandler ah = new AHandler();
        PostHandler bh = new BHandler();
        ah.setHandler(bh);
        Post post = new Post();
        post.setContent("正常内容，广告，游戏推广");
        System.out.println("过滤前的内容：" + post.getContent());
        ah.handleRequest(post);
        System.out.println("过滤后的内容：" + post.getContent());

        Number n = new Number();
        n.threadOperation();
//        System.out.println("最终结果：" + n.getAi());
        System.out.println("最终结果：" + n.getI());
    }
}
